import React from "react";

const Login = () => {

    React.useEffect(()=>{
        if(React.Business.id){
            React.navigate(-1)
        }
    },[])

    let [business,setBusiness] = React.useState({
       
    })

    const onFinish = async (values:any) => {
        let result = await React.HTTP.post("/business/login",values)
        if(result.code == 1){
            // 存储cookies
            React.Cookie.save("business",result.data)
            React.success(result.msg,()=>{
                React.navigate("/business/index")
                // 刷新跳转
                // location.href = "/business/index"
            })
        }else{
            React.error(result.msg);
            return false
        }
    }
    
    return (
        <>
            <link rel="stylesheet" href="/assets/css/login.css" />
            <div className="login">
                <React.UI.Form
                    name='form'
                    initialValues={business}
                    onFinish={onFinish}
                    layout='horizontal'
                    footer={
                        <React.UI.Button block type='submit' color='primary' size='large'>
                            登录
                        </React.UI.Button>
                    }
                >
                    <React.UI.Form.Header>登录</React.UI.Form.Header>
                    <React.UI.Form.Item name='mobile' label='手机号' rules={[{ required: true, message: "请输入手机号" }, { pattern: /^1[3-9]{1}\d{9}$/, message: "手机号格式不正确" }]}>
                        <React.UI.Input type="mobile" placeholder='请输入手机号' />
                    </React.UI.Form.Item>
                    <React.UI.Form.Item name='password' label='密码' rules={[{ required: true, message: "请输入密码" }, { min: 6, message: "密码长度不少于6位" }, { max: 15, message: "密码长度大于15位" }]}>
                        <React.UI.Input type="password" placeholder='请输入密码' />
                    </React.UI.Form.Item>
                </React.UI.Form>
                <div className="tips">
                    <div>忘记密码</div>
                    <React.Router.Link to={"/business/register"}>注册账号</React.Router.Link>
                </div>

            </div>
        </>
    )
}


export default Login
